/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidade;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bruno
 */
@Entity
@Table(name = "permissaoUsuario")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PermissaoUsuario.findAll", query = "SELECT p FROM PermissaoUsuario p"),
    @NamedQuery(name = "PermissaoUsuario.findByIdpermissoes", query = "SELECT p FROM PermissaoUsuario p WHERE p.idpermissoes = :idpermissoes"),
    @NamedQuery(name = "PermissaoUsuario.findByCaminho", query = "SELECT p FROM PermissaoUsuario p WHERE p.caminho = :caminho"),
    @NamedQuery(name = "PermissaoUsuario.findByAccao", query = "SELECT p FROM PermissaoUsuario p WHERE p.accao = :accao")})
public class PermissaoUsuario implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idpermissoes")
    private Integer idpermissoes;
    @Size(max = 45)
    @Column(name = "caminho")
    private String caminho;
    @Size(max = 45)
    @Column(name = "accao")
    private String accao;
    @JoinTable(name = "tipo_permissao_usuario", joinColumns = {
        @JoinColumn(name = "idPermissoes", referencedColumnName = "idpermissoes")}, inverseJoinColumns = {
        @JoinColumn(name = "idTipoUsuario", referencedColumnName = "idTipoUsuario")})
    @ManyToMany
    private Collection<TipoUsuario> tipoUsuarioCollection;

    public PermissaoUsuario() {
        this.idpermissoes=0;
    }

    public PermissaoUsuario(Integer idpermissoes) {
        this.idpermissoes = idpermissoes;
    }

    public Integer getIdpermissoes() {
        return idpermissoes;
    }

    public void setIdpermissoes(Integer idpermissoes) {
        this.idpermissoes = idpermissoes;
    }

    public String getCaminho() {
        return caminho;
    }

    public void setCaminho(String caminho) {
        this.caminho = caminho;
    }

    public String getAccao() {
        return accao;
    }

    public void setAccao(String accao) {
        this.accao = accao;
    }

    @XmlTransient
    public Collection<TipoUsuario> getTipoUsuarioCollection() {
        return tipoUsuarioCollection;
    }

    public void setTipoUsuarioCollection(Collection<TipoUsuario> tipoUsuarioCollection) {
        this.tipoUsuarioCollection = tipoUsuarioCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idpermissoes != null ? idpermissoes.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PermissaoUsuario)) {
            return false;
        }
        PermissaoUsuario other = (PermissaoUsuario) object;
        if ((this.idpermissoes == null && other.idpermissoes != null) || (this.idpermissoes != null && !this.idpermissoes.equals(other.idpermissoes))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getAccao();
    }
    
}
